//
//  GUILabel.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/3/29.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "GUILabel.h"

@implementation GUILabel

//- (void)setContentInset:(UIEdgeInsets)contentInset {
//    _contentInset = contentInset;
//    NSString *tempString = self.text;
//    self.text = @"";
//    self.text = tempString;
//}

// 修改绘制文字的区域，edgeInsets增加bounds
-(CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines
{
    
    /*
     调用父类该方法
     注意传入的UIEdgeInsetsInsetRect(bounds, self.edgeInsets),bounds是真正的绘图区域
     */
    CGRect rect = [super textRectForBounds:UIEdgeInsetsInsetRect(bounds,
                                                                 self.contentInset) limitedToNumberOfLines:numberOfLines];
    //根据edgeInsets，修改绘制文字的bounds
    rect.origin.x -= self.contentInset.left;
    rect.origin.y -= self.contentInset.top;
    rect.size.width += self.contentInset.left + self.contentInset.right;
    rect.size.height += self.contentInset.top + self.contentInset.bottom;
    return rect;
}


-(void)drawTextInRect:(CGRect)rect {
    [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.contentInset)];
}

@end
